<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片压缩工具</title>
    <link rel="stylesheet" href="styles.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body>
    <header>
        <h1>在线图片压缩工具</h1>
        <p>简单易用的网页图片压缩，保持高质量的同时减小文件大小</p>
    </header>

    <main>
        <section class="upload-container" id="upload-area">
            <div class="upload-box" id="drop-zone">
                <i class="fas fa-cloud-upload-alt"></i>
                <h2>拖放图片到这里</h2>
                <p>或者</p>
                <label for="file-input" class="upload-button">选择图片</label>
                <input type="file" id="file-input" accept="image/*" hidden>
                <p class="note">支持: JPG, PNG, WEBP (最大10MB)</p>
            </div>
        </section>

        <section class="compression-container" id="compression-area" style="display: none;">
            <div class="image-preview-container">
                <div class="preview-box">
                    <h3>原图</h3>
                    <div class="preview-wrapper">
                        <img id="original-image" src="" alt="原图预览">
                    </div>
                    <div class="image-info" id="original-info">
                        尺寸: <span id="original-dimensions">0 x 0</span><br>
                        大小: <span id="original-size">0 KB</span>
                    </div>
                </div>

                <div class="preview-box">
                    <h3>压缩后</h3>
                    <div class="preview-wrapper">
                        <img id="compressed-image" src="" alt="压缩后预览">
                    </div>
                    <div class="image-info" id="compressed-info">
                        尺寸: <span id="compressed-dimensions">0 x 0</span><br>
                        大小: <span id="compressed-size">0 KB</span><br>
                        节省: <span id="size-reduction">0%</span>
                    </div>
                </div>
            </div>

            <div class="compression-controls">
                <div class="control-group">
                    <label for="quality-slider">压缩质量:</label>
                    <input type="range" id="quality-slider" min="0" max="100" value="80" class="slider">
                    <span id="quality-value">80%</span>
                </div>

                <div class="control-group">
                    <label for="max-width">最大宽度 (可选):</label>
                    <input type="number" id="max-width" placeholder="原始宽度">
                    <span>像素</span>
                </div>

                <div class="control-group">
                    <label for="format-select">输出格式:</label>
                    <select id="format-select">
                        <option value="jpeg">JPEG</option>
                        <option value="png">PNG</option>
                        <option value="webp">WEBP</option>
                    </select>
                </div>

                <div class="buttons">
                    <button id="compress-btn" class="primary-button">压缩图片</button>
                    <button id="download-btn" class="secondary-button" disabled>下载压缩图片</button>
                    <button id="reset-btn" class="text-button">重新上传</button>
                </div>
            </div>
        </section>
    </main>

    <footer>
        <p>© 2025 图片压缩工具 | 使用HTML5 Canvas技术构建 | Alex</p>
    </footer>

    <script src="script.js"></script>
</body>
</html> 